package com.gameLogic.scene
{
	import laya.display.Sprite;
	import laya.resource.Texture;
	import laya.utils.Handler;

	public class MapTile
	{
		private var _row:int;
		private var _col:int;
		private var _resUrl:String;
		private var _isLoaded:Boolean = false;
		private var _parent:Sprite;
		private var _disObj:Sprite;
		
		public function MapTile(row:int, col:int, parent:Sprite)
		{
			_row = row;
			_col = col;
			_parent = parent;
			var id:String = _row + "_" + _col;
			_resUrl = "../../res/map_001/" + id + ".jpg";
			_disObj = new Sprite();
		}
		
		public function loadTile():void
		{
			//trace("load: " + _resUrl);
			Laya.loader.load(_resUrl, Handler.create(this, onLoadCmp));
			//SpawnerManager.instance.onTileLoaded(_col, _row);
		}
		
		private function onLoadCmp():void
		{
			_isLoaded = true;
			var t:Texture = Laya.loader.getRes(_resUrl);
			_disObj.graphics.drawTexture(t,0,0);
			_disObj.x = _col * 300;
			_disObj.y = _row * 300;
			_parent.addChild(_disObj);
		}
		
		public function unloadTile():void
		{
			//SpawnerManager.instance.onTileUnloaded(_col, _row);
			return;
			_disObj.graphics.clear();
			if(!_isLoaded)
				Laya.loader.cancelLoadByUrl(_resUrl);
			else
				Laya.loader.clearRes(_resUrl, true);
			_isLoaded = false;
			_parent.removeChild(_disObj);
			//trace("unloadTile: " + _resUrl);
		}
		
	}
}